package com.eastfair.notice.controller;

import com.eastfair.notice.dto.MsgLogPageQuery;
import com.eastfair.notice.dto.MsgLogSaveDTO;
import com.eastfair.notice.dto.MsgLogUpdateDTO;
import com.eastfair.notice.entity.MsgLog;
import com.eastfair.notice.service.MsgLogService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 消息发送记录
 * </p>
 *
 * @author liuxiaobai
 * @date 2021-08-04
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/msgLog")
@Api(value = "MsgLog", tags = "消息发送记录")
public class MsgLogController extends SuperController<MsgLogService, Long, MsgLog, MsgLogPageQuery, MsgLogSaveDTO, MsgLogUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<MsgLog> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<MsgLog> msgLogList = list.stream().map((map) -> {
            MsgLog msgLog = MsgLog.builder().build();
            //TODO 请在这里完成转换
            return msgLog;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(msgLogList));
    }
}
